<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "{{%hj_part}}".
 *
 * @property int $id 主键ID
 * @property string $part_name 角色名称
 * @property int|string creater
 * @property int create_at
 * @property int|string updater
 * @property int update_at
 */
class Part extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%part}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['create_at', 'update_at', 'creater', 'updater'], 'integer'],
            [['part_name','name'], 'string', 'max' => 255],
            [['part_name'], 'unique'],
        ];
    }

    public function extraFields()
    {
        $fields['username'] = function($model) {
            return $model->user->name;
        };
        return $fields;
    }

    public function getUser() {
        return $this->hasOne(User::class, ['id' => 'creater']);
    }
}
